package phase1;
import java.util.*;


public class FindByPath implements Algorithm {
	DictionaryChecking dc=new DictionaryChecking();
	//recursive method
	//block:start point, str:the temp string result from parent blocks
	//strVector:the right words vector, wordLength:limited word length on searching
	public void findTheWords(Block block,String str,Vector<String> strVector,int wordLength){
		//base case
		//if word length equals to 1, it just checks the current block
		if(wordLength==1){
			String temp;
			int blockCharCount=block.getNumOfChar();
			for(int i=0;i<blockCharCount;i++){
				temp=str+block.getChar(i);
				if(dc.check(temp)){
					if(!strVector.contains(temp))
						strVector.add(temp);
				}
			}	
		}else{
			//else append the char at current block and check if it is valid
			//pass to next block with that string
			String temp;
			int blockCharCount=block.getNumOfChar();
			Vector<Block> nextBlocks=block.getNextBlock();
			int nextBlocksSize=nextBlocks.size();
			for(int i=0;i<blockCharCount;i++){
				temp=str+block.getChar(i);
				if(dc.check(temp)){
					if(!strVector.contains(temp))
						strVector.add(temp);
				}
				for(int j=0;j<nextBlocksSize;j++){
					findTheWords(nextBlocks.get(j),temp,strVector,wordLength-1);
				}
			}
		}
	}

}
